package com.itgacl.minio.policy;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class BucketPolicyFactory {

    static Map<String, BucketPolicy> operationMap = new HashMap<>();
    static {
        operationMap.put(BucketPolicyContent.READ, new BucketReadPolicy());// 只读
        operationMap.put(BucketPolicyContent.WRITE, new BucketWritePolicy());// 只写
        operationMap.put(BucketPolicyContent.READ_WRITE, new BucketReadWriterPolicy());// 读写
    }

    public static BucketPolicy getBucketPolicy(String policy) {
        BucketPolicy object = getDefaultBucketPolicy();
        if (!StringUtils.isEmpty(policy)) {
            object = operationMap.get(policy);
            if (object == null) {
                object = getDefaultBucketPolicy();//默认读写权限
            }
        }
        return object;
    }

    public static BucketPolicy getDefaultBucketPolicy(){
        return operationMap.get(BucketPolicyContent.READ_WRITE);
    }
}
